const {
	db,
	dbCmd,
	result_success,
	result_error,
	appletInfoCollection,
	collectionCollection,
	userCollection
} = require('../../common/constants')
module.exports = async function(params = {}) {
	const token = this.getUniIdToken()
	if (!token) {
		return result_error('登录失效,请重新登录')
	}
	let payload = await this.uniID.checkToken(token)
	if (payload.code) {
		return payload
	}
	let type = params.type
	let way = params.way
	let id = params.id
	let cUser = await userCollection.doc(payload.uid).get()
	cUser = cUser.data[0]
	if(!cUser.app_id){
		return result_success({})
	}
	//获取当前应用
	let appletInfoData = await appletInfoCollection.doc(cUser.app_id).get()
	appletInfoData = appletInfoData.data[0] 
	let miniId = appletInfoData.wechat.gh_id
	let alipay_id = appletInfoData.alipay.app_id
	let imageUrl =
		'https://7463-tcb-fy6f7f4nm7mhifi-6c366c810511-1308293149.tcb.qcloud.la/fukuan/20230612160500.png'
	let title = "开通会员"
	let path = '/sub-user/pages/member/member-not'
	if (way === 'recharge') {
		let recharge = await db.collection('wmzmall-recharge').doc(id).get()
		recharge = recharge.data[0]
		if (!recharge) {
			return result_error()
		}
		title = '储值' + recharge.money + "元,到账:" + recharge.arrival + "元"
		path = '/sub-user/pages/wallet/wallet'
	}
	let shareRes = await db.collection('wmzmall-app-share').where({
		shop_id: appletInfoData._id
	}).get()
	shareRes = shareRes.data[0]
	if (shareRes && shareRes.collection_img) {
		imageUrl = shareRes.collection_img
	}
	let webUrl = "https://mall.web.wmeizi.com/skipapplet.html?appId=" + alipay_id
	let summary = ''
	return result_success({
		title: title,
		miniId: miniId,
		path: path,
		imageUrl: imageUrl,
		webUrl: webUrl,
		summary: summary
	})
}